<template>

  <div class="login-container">
    <el-card class="login-card">
      <div slot="header" class="login-header">
        <span>用户登录</span>
      </div>
      <el-form :model="loginForm"  ref="loginForm" class="login-form" label-width="0px">

<!--        输入id-->
        <el-form-item prop="username">
            <el-input v-model="loginForm.id" prefix-icon="el-icon-user" placeholder="请输入学号" clearable></el-input>
        </el-form-item>
<!--    输入学生姓名-->
        <el-form-item prop="password">
            <el-input v-model="loginForm.stuname" prefix-icon="el-icon-lock" placeholder="请输入姓名" show-password></el-input>
        </el-form-item>
<!--        登录按钮-->
        <el-form-item>
          <el-button type="primary" @click="handleLogin" class="login-button" >登录</el-button>
        </el-form-item>

      </el-form>
    </el-card>
  </div>

</template>

<script>
import axios from 'axios'

export default {
  name: 'LoginView',
  data() {
    return {
      // 登录表单数据
      loginForm: {
        id: '',
        stuname: ''
      },
    }
  },
  methods: {
    handleLogin() {

      axios.post('http://localhost:8081/Stu/idandname',null, {
                                                            //后端接收参数不是json所以data是空用的直接传参
        params: {
          id: this.loginForm.id,
          name: this.loginForm.stuname
        }
      }).then(response => {
        // 登录成功处理
        this.$message({
          message: '登录成功',
          type: 'success'
        })
        console.log('登录响应:', response.data)
      }).catch(error => {
        // 登录失败处理
        this.$message({
          message: '登录失败，请检查用户名和密码',
          type: 'error'
        })
        console.error('登录错误:', error)
      })

    }
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f0f2f5;
}

.login-card {
  width: 400px;
  max-width: 90%;
}

.login-header {
  text-align: center;
  font-size: 20px;
  font-weight: bold;
}

.login-form {
  margin-top: 20px;
}

.login-button {
  width: 100%;
}
</style>